package com.hogan.basiclibrary.base.baseApi.protocol;


import com.hogan.basiclibrary.base.baseApi.exception.ServerApiException;

/**
 * Created by chenhu on 2017/8/16.
 * 易源数据协议
 */

public class YiYuanProtocol<T> implements BaseProtocol<T> {
    private int showapi_res_code;
    private String showapi_res_error;
    private T showapi_res_body;


    public T getShowapi_res_body() {
        return showapi_res_body;
    }

    public void setShowapi_res_body(T showapi_res_body) {
        this.showapi_res_body = showapi_res_body;
    }

    public int getShowapi_res_code() {
        return showapi_res_code;
    }

    public void setShowapi_res_code(int showapi_res_code) {
        this.showapi_res_code = showapi_res_code;
    }

    public String getShowapi_res_error() {
        return showapi_res_error;
    }

    public void setShowapi_res_error(String showapi_res_error) {
        this.showapi_res_error = showapi_res_error;
    }


    @Override
    public Object startProtocol() {
        return handleResult(getShowapi_res_code(), getShowapi_res_error());
    }

    protected Object handleResult(int result, String message) {
        if (result == 0) {
            return getShowapi_res_body();
        } else {
            return new ServerApiException(result, message);

        }
    }
}
